package cn.wisenergy.pai.monitor.linux.parser;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class NetWork implements Serializable{
	private static final long serialVersionUID = -3975054408680017474L;
	//网络接受速率
	private long netaccept;
	//网络发送速率
	private long netsend;
	
	public float getNetaccept() {
		return netaccept;
	}
	public void setNetaccept(long netaccept) {
		this.netaccept = netaccept;
	}
	public float getNetsend() {
		return netsend;
	}
	public void setNetsend(long netsend) {
		this.netsend = netsend;
	}
	@Override
	public byte[] toBytes() throws IOException {
		ByteArrayOutputStream bytesOutput=new ByteArrayOutputStream();
		DataOutputStream dataOutput=new DataOutputStream(bytesOutput);
		dataOutput.writeLong(netaccept);
		dataOutput.writeLong(netsend);
		byte[] result=bytesOutput.toByteArray();
		dataOutput.close();
		bytesOutput.close();
		return result;
	}
	@Override
	public void toObject(byte[] ab) throws IOException {
		ByteArrayInputStream bytesInput=new ByteArrayInputStream(ab);
		DataInputStream dataInput=new DataInputStream(bytesInput);
		if(dataInput.available()>0){
			netaccept=dataInput.readLong();
		}
		if(dataInput.available()>0){
			netsend=dataInput.readLong();
		}
		dataInput.close();
		bytesInput.close();
		
	}
	@Override
	public String toString() {
		return "Net [netaccept=" + netaccept + ", netsend=" + netsend + "]";
	}
	
}
